<template>
  <div class="auto">
    <div class="row app-row">
      <div class="col-xs-3">
        <p class="text-left">抄表员</p>
      </div>
      <div class="col-xs-9">
        {{userInfo.name}}
      </div>
    </div>
    <div class="row app-row">
      <div class="col-xs-3">
        <p class="text-left">起时间</p>
      </div>
      <div class="col-xs-9">
        <datepicker
           :value.sync="model.startDate"
           :format="'yyyy-MM-dd'"
           v-model="model.startDate"
           :show-reset-button="reset">
         </datepicker>
        <!-- <input type="text" class="search_input" v-model="model.startDate" placeholder="请输入起下发时间"/> -->
      </div>
    </div>
    <div class="row app-row">
      <div class="col-xs-3">
        <p class="text-left">止时间</p>
      </div>
      <div class="col-xs-9">
        <datepicker
           :value.sync="model.endDate"
           :format="'yyyy-MM-dd'"
           v-model="model.endDate"
           :show-reset-button="reset">
         </datepicker>
        <!-- <input type="text" class="search_input" v-model="model.endDate" placeholder="请输入止下发时间"/> -->
      </div>
    </div>
    <div class="row" style="margin-top: 20px;">
      <button type="button" v-if="!show" class="btn btn-success btn-lg" style="width: 100%;" @click="search()">搜索</button>
      <button type="button" v-if="show" class="btn btn-success btn-lg" style="width: 100%;" @click="handUpdate()">全部上传</button>
    </div>
    <div class="auto" style="padding-top: 20px;">
      <finish-hand-info v-if="showHandInfo" :data="rows"></finish-hand-info>
    </div>
  </div>
</template>
<script>
  import AppData from '../../stores/AppData'
  import * as Util from '../Util'
  export default {
    title: '计划管理',
    data () {
      return {
        model: {
          startDate: '',
          endDate: ''
        },
        showHandInfo: false,
        show: false,
        rows: {},
        userInfo: {}
      }
    },
    ready () {
      this.userInfo = Object.assign({}, this.userInfo, AppData.loginUser)
      this.model.startDate = `${Util.toStandardYearMonth()}-01`
      this.model.endDate = Util.toStandardDateString()
    },
    methods: {
      search () {
        if (this.model.startDate === '') {
          this.model.startDate = `${Util.toStandardYearMonth()}-01`
        }
        if (this.model.endDate === '') {
          this.model.endDate = Util.toStandardDateString()
        }
        let params = {
          condition: '1 = 1',
          startDate: this.model.startDate,
          endDate: this.model.endDate,
          f_inputtor: this.userInfo.name
        }
        let result = this.$androidUtil.bzLogic('getHandMeterInfo', {data: params})
        if (result.state === 0) {
          if (result.data.data.length > 0) {
            this.show = true
            this.showHandInfo = true
            this.rows = [...result.data.data]
          }
        } else {
          this.$showMessage(`加载数据失败, 返回码: ${result.code}, 错误信息：${result.data}`)
          this.show = false
        }
      },
      handUpdate () {
        this.$androidUtil.bzLogic('uploadHandMeterAll', {data: this.rows})
        this.show = true
      }
    }
  }
</script>
<style>
  .search_input {
    border: 0;
    outline: none;
  }
  .app-row {
    background-color: white;
    padding: 10px 10px 0 10px;
    border-bottom: 1px solid rgba(235, 235, 235, 0.5);
  }
</style>
